package cn.donting.jme.edit.context;

import cn.donting.jme.edit.EditorState;
import cn.donting.jme.edit.context.input.FxKeyInput;
import cn.donting.jme.edit.context.input.FxMouseInput;
import com.jme3.input.KeyInput;
import com.jme3.input.MouseInput;
import com.jme3.system.lwjgl.LwjglOffscreenBuffer;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.Pane;
import lombok.extern.slf4j.Slf4j;


/**
 * 携带fx 鼠标键盘输入的 LwjglOffscreenBuffer
 * FXCanvas 没有键盘事件
 * @see com.jme3.system.lwjgl.LwjglOffscreenBuffer
 * TODO:LwjglOffscreenBuffer 的
 *            private int width;
 *            private int height;
 *            没有做出改变,值始终为 settings 的初始值
 * @author donting
 */
@Slf4j
public class InputLwjglOffscreenBuffer extends LwjglOffscreenBuffer implements Runnable {


    /**
     * Canvas 没有键盘事件，因此在canvas 上加一层透明的Pane 用来接收事件
     * @return
     */
    @Override
    public KeyInput getKeyInput() {
        Canvas canvas = EditorState.getJmeEditSceneApp().getCanvas();
        Pane lookup = (Pane)canvas.getScene().lookup("#inputPlan");
        FxKeyInput fxKeyInput = new FxKeyInput();
        fxKeyInput.bind(lookup);
        return fxKeyInput;
    }

    /**
     * @see InputLwjglOffscreenBuffer#getKeyInput()
     * @return
     */
    @Override
    public MouseInput getMouseInput() {
        FxMouseInput fxMouseInput = new FxMouseInput();
        Canvas canvas = EditorState.getJmeEditSceneApp().getCanvas();
        Pane lookup = (Pane)canvas.getScene().lookup("#inputPlan");
        fxMouseInput.bind(lookup);
        return fxMouseInput;
    }

}
